import React from 'react'


export default class Input extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      value:''
    }
  }

  render(){
    return (
      <div>
        <input value={this.state.value}
               style={{width:'100%',height:'40px',fontSize:'28px'}} type="text"
               onKeyUp={this.keyUpHandle.bind(this)}
               onChange={this.changeHandle.bind(this)}/>
      </div>
    )
  }
  changeHandle(e){
    console.log(e.target.value);
    this.setState({value:e.target.value})
  }
  //回车的时候将参数传递到父组件中,然后清空值,trip为将字符串两头的空格去掉
  keyUpHandle(e){
    let value = this.state.value;
    if(e.keyCode===13 && value.trim()){
      this.props.submitn(value);
      this.setState({value:''})
    }
  }

}